package com.example.cunion.controller;

import com.example.cunion.common.R;
import com.example.cunion.controller.form.ActClassForm;
import com.example.cunion.controller.form.PageFom;
import com.example.cunion.entity.ActClass;
import com.example.cunion.service.ActClassService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/actClass")
public class ActClassController {

    @Resource
    private ActClassService actClassService;

    @PostMapping("/searchAllActClass")
    public R searchAllActClass(@RequestHeader String token, @RequestBody ActClassForm actClassForm){
        String position = actClassForm.getPosition();
        ArrayList<HashMap> map = actClassService.searchAllActClass(position);
        return R.ok("查询所有成功！").put("result", map);
    }

    @PostMapping("/addActClassByMp")
    public R addActClassByMp(@RequestHeader("token") String token, @RequestBody ActClass actClass) {
        actClassService.addActClass(actClass);
        return R.ok();
    }

    @GetMapping("/deleteActClassByMp")
    public R deleteActClassByMp(@RequestHeader("token") String token, @RequestParam("actClassId") String actClassId) {
        actClassService.deletedActClass(actClassId);
        return R.ok();
    }
    @PostMapping("/updateActClassByMp")
    public R updateActClassByMp(@RequestHeader("token") String token, @RequestBody ActClass actClass) {
        actClassService.updateActClass(actClass);
        return R.ok();
    }
    @PostMapping("/searchActClassByMp")
    public R searchActClassByMp(@RequestHeader("token") String token, @RequestBody PageFom form){
        List<ActClass> list = actClassService.searchActClass(form.getStart(), form.getLength());
        return R.ok().put("result", list);
    }

}
